<template>
	<view>
			
		<template lang="wxml">
			<view class="home">

		        <search/>
					<u-icon name="arrow-upward" size="38" v-show="scrollTop>200" @tap="returnTap"></u-icon> 
				<!-- 轮播图 -->
				<swiper class="swiper">
					<swiper-item v-for="(item,index) in swiperList" :key="index">
						<navigator  :url="'/pages/list/list?id='+item.goods_id">
							<image :src="item.image_src" />
						</navigator>
					</swiper-item>
				</swiper>
		        
				<!-- 导航区 -->
				<view class="nav">
					<navigator  v-for="(item,index) in navList" :key="index">
						<image :src="item.image_src" />
					</navigator>
				</view>
		
				<!-- 楼层数据 -->
				<view class="floors">
					<view class="floor" v-for="(item,index) in floorList" :key="index">
						<view class="title">
							<image :src="item.floor_title.image_src" />
						</view>
						<view class="imgs">
							<navigator v-for="i in item.product_list" :key="i.name"  class="item" :url="'/pages/goods-list/goods-list?query='+i.name">
								<image :src="i.image_src" />
							</navigator>
						</view>
					</view>		
				</view>	
					<button></button>
			</view>
		</template>
	</view>
</template>
<script>
	export default {
		data(){
			return {
				swiperList:[],
				navList:[],
				floorList:[],
				scrollTop:0
				
			}
		},
		onShareAppMessage () {
		    return {
		        title: '来传智，学前端，成赢家!',
		        path:"/pages/index/index",
		        imageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607512079312&di=e292702c32cccaf4b133c3dcfe99b8ff&imgtype=0&src=http%3A%2F%2Fbmp.skxox.com%2F201605%2F06%2Flanou.093918.jpg'
		    }
		},
		  onLoad(){
			 this.getswiperList()
			 this.getnavList()
			 this.getfloorList()
			 uni.showShareMenu({
			 			withShareTicket: true,
			 			menus: ["shareAppMessage", "shareTimeline"]
			 		})
		},
		async onPullDownRefresh() {
			console.log('refresh');
			await	this.getswiperList()
			await	this.getnavList()
			await	this.getfloorList()
			uni.stopPullDownRefresh();
				
			},
			onPageScroll(e){
			    // console.log(e.scrollTop);
                this.scrollTop=e.scrollTop
			  },
		methods:{
			async  getswiperList (){
				let res = await this.$request({
				  url: "/api/public/v1/home/swiperdata",
				});
				console.log(res);
				this.swiperList=res.message 
			} ,
			async  getnavList (){
				let res = await this.$request({
				  url: "/api/public/v1/home/catitems",
				});
				console.log(res,'navList');
				this.navList=res.message 
			} ,
			async  getfloorList (){
				let res = await this.$request({
				  url: "/api/public/v1/home/floordata",
				});
				console.log(res,'floorList');
				this.floorList=res.message 
			} ,
			returnTap(){
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			}
			}

         

}
</script>

<style lang="less" scoped>


	.swiper {
		height: 340rpx;
		image {
			width: 750rpx;
			height: 340rpx;
		}
	}


	.nav {
		display: flex;
		navigator {
			flex:1;
			text-align:center;
			image {
				width: 128rpx;
				height: 140rpx;
				margin: 20rpx 0;
			}
		}
	}


	.floors{
		// 公共楼层
		.floor {
			.title {
				box-sizing: border-box;
				padding-top: 20rpx;
				padding-left: 16rpx;
				background-color: #f4f4f4;
				image {
					width: 100%;
					height: 60rpx;
				}
			}
			.imgs {
				padding: 20rpx 12rpx;
				overflow: hidden;
				.item {
					float: left;
					margin-right: 10rpx;
					margin-bottom: 10rpx;
				}
				.item image {
					width: 100%;
					height: 100%;
				}
				.item:nth-child(1){
					width: 232rpx;
					height: 386rpx;
				}
				.item:nth-child(2),.item:nth-child(5){
					width: 273rpx;
					height: 188rpx;
				}
				.item:nth-child(3),.item:nth-child(4){
					width: 203rpx;
					height: 188rpx;
				}
				// 3 5 没有右侧margin
				.item:nth-child(3),.item:nth-child(5){
					margin-right: 0;
				}
			}
		}

		// 第一楼层：less嵌套结构，在下面覆盖上面样式的话，注意嵌套结构一样；
		.floor:nth-child(1) {
			.imgs {
				// n:0; 2 3 4 5
				.item:nth-child(n+2){
					width: 236rpx;
					height: 188rpx;
				}
			}
		}
	}
    .u-icon {
     display: inline-block;
	 position: fixed;
	 right:0;
	 bottom:150rpx;
	 z-index: 1;
	}
</style>
